package com.showcai.service.provider.user.controller;

import com.github.pagehelper.PageInfo;
import com.showcai.module.vo.User;
import com.showcai.service.provider.user.service.UserService;
import com.showcai.tools.myRunTime.MyRunTimeExcption;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created by Baggio on 2018-6-25.
 */
@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    UserService userService;

    @RequestMapping(value = "/get/{id}",method = RequestMethod.POST)
    public User get(@PathVariable("id") Long id) {
        System.out.println("getUserById");
        if(id==1){
            throw new MyRunTimeExcption("id is 1");
        }
        return userService.getUserByid(id);
    }

    @RequestMapping("/userList")
    public List<User> userList(@RequestParam Map<String,String> map) {
        return userService.getUserList(map);
    }

    @RequestMapping(value="/getUserListPageInfo")
    public PageInfo getUserListPageInfo(@RequestParam Map<String,String> map) {
        PageInfo pageInfo= userService.getUserListPageInfo(map);
        return pageInfo;
    }

    @RequestMapping("/modify")
    public User modify(@RequestParam User user) {
        userService.mdifiyUser(user);
        return user;

    }

}
